package com.zhu.dao;

import com.zhu.pojo.User;
import com.zhu.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    private Connection connection;
    private PreparedStatement preparedStatement;
    private ResultSet resultSet;

    public User getUser(User user) throws SQLException {
        connection = JDBCUtil.getInstance().getConnection();
        preparedStatement = connection.prepareStatement("select * from user where username=? AND password=?");
        preparedStatement.setString(1,user.getUsername());
        preparedStatement.setString(2,user.getPassword());
        resultSet = preparedStatement.executeQuery();
        User getUser = null;
        while (resultSet.next()) {
            getUser = new User();
            getUser.setUsername(resultSet.getString("username"));
            getUser.setPassword(resultSet.getString("password"));

        }
        return getUser;
    }
}
